<template>
  <u--input
      placeholder="扫码数据"
      border="surround"
      :disabled="true"
      v-model="this.scanCode"
  ></u--input>
</template>
<script  >
import UInput from "../../../../uview-ui/components/u--input/u--input.vue";

export default  {
  components: {UInput},
  data() {
    return {
      scanCode: '',
    }
  },
  methods: {
    initScan() {
      let barcodeModel = uni.requireNativePlugin("iData-BarcodePlugin-BarcodeModule")
      barcodeModel.initScan((ret) => {
        if (ret.code === 'success') {
          console.log("初始化成功");
        }
      });
      let globalEvent = uni.requireNativePlugin('globalEvent');
      let that = this;
      globalEvent.addEventListener('iDataBarcodeEvent', function(res) {
        that.scanCode =  res.barcode;
      });
    }

  },
  onLoad() {
    this.initScan();
  }
}
</script>
